package com.ruoyi.app.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.TDeliveryAddress;
import com.ruoyi.system.domain.User;
import com.ruoyi.system.service.ITDeliveryAddressService;
import com.ruoyi.utils.AppUserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "小程序端-收货地址")
@RestController
@RequestMapping("/app/aboutUs")
public class AddressController {

    @Autowired
    private ITDeliveryAddressService tDeliveryAddressService;


    @ApiOperation("保存收货地址")
    @PostMapping("/saveAddress")
    private AjaxResult saveAddress(TDeliveryAddress tDeliveryAddress){
        String appUser = AppUserUtils.getAppUserId();
        tDeliveryAddress.setUserId(appUser);
        return AjaxResult.success(tDeliveryAddressService.insertTDeliveryAddress(tDeliveryAddress));
    }

    @ApiOperation("获取用户收货地址")
    @PostMapping("/getAddress")
    private AjaxResult getAddress(){
        User appUser = AppUserUtils.getAppUser();
        TDeliveryAddress tDeliveryAddress = new TDeliveryAddress();
        tDeliveryAddress.setUserId(appUser.getId());
        return AjaxResult.success(tDeliveryAddressService.selectTDeliveryAddressList(tDeliveryAddress));
    }
}
